/*
 * UpdateController.java
 *
 * Created on March 20, 2007, 6:13 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.samlam;

import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 * @author Sam
 */
public class UpdateController {
    
    /** Creates a new instance of UpdateController */
    public UpdateController() {
    }
    
    
    ////////////////////////////////////////////////////////
    // Singleton
    
    public void postSale(Transaction tx){
        if (tx.getStatus() == "complete"){
            
        }
       // transactionDAO.getInstance().save(tx);
        /*
        //update inventory
        Statement stmt = conn.createStatement();
        stmt.executeUpdate("UPDATE Inventory set inventory_id='"+inventory.getId()+"', location='"+inventory.getLocation()+"', quantity='"+inventory.getQuantity()+"'WHERE inventory_id='"+inventory.getId()+"'");
        stmt.close();
        //update account
        Statement stmt = conn.createStatement();
        stmt.executeUpdate("UPDATE AccountRecievable set acctsRecievable_id='"+acctsRecievable.getId()+"', companyName='"+acctsRecievable.getName()+"'WHERE acctsRecievable_id='"+acctsRecievable.getId()+"'");
        stmt.close();
        // update cash
        */
         // update customer account balance
        
    }
    
    public void post_Sale(Transaction tx) throws Exception{
       try { Connection conn = ConnectionPool.getInstance().get();
            try {
                
                TransactionDAO.getInstance().save(tx, conn);
                conn.commit();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        
            ConnectionPool.getInstance().release(conn);
        } catch (ConnectionPoolException ex) {
            ex.printStackTrace();
        }
    }
        
}
